#include "StyleManager.hpp"
#include "StyleBuilder.hpp"

#define WHITE_PAWN_IMG "./pixs/white/std/pawn.png"
#define WHITE_ROOK_IMG "./pixs/white/std/rook.png"
#define WHITE_KNIGHT_IMG "./pixs/white/std/knight.png"
#define WHITE_BISHOP_IMG "./pixs/white/std/bishop.png"
#define WHITE_QUEEN_IMG "./pixs/white/std/queen.png"
#define WHITE_KING_IMG "./pixs/white/std/king.png"

#define WHITE_SELECT_PAWN_IMG "./pixs/white/select/pawn.png"
#define WHITE_SELECT_ROOK_IMG "./pixs/white/select/rook.png"
#define WHITE_SELECT_KNIGHT_IMG "./pixs/white/select/knight.png"
#define WHITE_SELECT_BISHOP_IMG "./pixs/white/select/bishop.png"
#define WHITE_SELECT_QUEEN_IMG "./pixs/white/select/queen.png"
#define WHITE_SELECT_KING_IMG "./pixs/white/select/king.png"

#define WHITE_CHOICE_PAWN_IMG "./pixs/white/choice/pawn.png"
#define WHITE_CHOICE_ROOK_IMG "./pixs/white/choice/rook.png"
#define WHITE_CHOICE_KNIGHT_IMG "./pixs/white/choice/knight.png"
#define WHITE_CHOICE_BISHOP_IMG "./pixs/white/choice/bishop.png"
#define WHITE_CHOICE_QUEEN_IMG "./pixs/white/choice/queen.png"
#define WHITE_CHOICE_KING_IMG "./pixs/white/choice/king.png"

#define BLACK_PAWN_IMG "./pixs/black/std/pawn.png"
#define BLACK_ROOK_IMG "./pixs/black/std/rook.png"
#define BLACK_KNIGHT_IMG "./pixs/black/std/knight.png"
#define BLACK_BISHOP_IMG "./pixs/black/std/bishop.png"
#define BLACK_QUEEN_IMG "./pixs/black/std/queen.png"
#define BLACK_KING_IMG "./pixs/black/std/king.png"

#define BLACK_SELECT_PAWN_IMG "./pixs/black/select/pawn.png"
#define BLACK_SELECT_ROOK_IMG "./pixs/black/select/rook.png"
#define BLACK_SELECT_KNIGHT_IMG "./pixs/black/select/knight.png"
#define BLACK_SELECT_BISHOP_IMG "./pixs/black/select/bishop.png"
#define BLACK_SELECT_QUEEN_IMG "./pixs/black/select/queen.png"
#define BLACK_SELECT_KING_IMG "./pixs/black/select/king.png"

#define BLACK_CHOICE_PAWN_IMG "./pixs/black/choice/pawn.png"
#define BLACK_CHOICE_ROOK_IMG "./pixs/black/choice/rook.png"
#define BLACK_CHOICE_KNIGHT_IMG "./pixs/black/choice/knight.png"
#define BLACK_CHOICE_BISHOP_IMG "./pixs/black/choice/bishop.png"
#define BLACK_CHOICE_QUEEN_IMG "./pixs/black/choice/queen.png"
#define BLACK_CHOICE_KING_IMG "./pixs/black/choice/king.png"

#define WHITE_CELL_IMG		"./pixs/cell/white2.png"
#define BLACK_CELL_IMG 		"./pixs/cell/black2.png"
#define HIGHLIGHT_WHITE_CELL_IMG	"./pixs/cell/choice_white.png"
#define HIGHLIGHT_BLACK_CELL_IMG	"./pixs/cell/choice_black.png"

#define BACKGROUND_IMG  "./data/bg.png"


StyleManager*	StyleManager::instance = 0;

StyleManager*	StyleManager::getInstance()
{
	if (StyleManager::instance == 0)
		StyleManager::instance = new StyleManager();
		
	return (StyleManager::instance);
}

StyleManager::StyleManager()
{
	try
	{
		StyleBuilder*	style_b = new StyleBuilder();
				
		// BACKGROUND
		style_b->setBackgroundPixmap(new QPixmap(BACKGROUND_IMG));
		
		// WHITE CELLS
		style_b->setCellPixmap(Chess::WHITE, Style::C_STANDARD, new QPixmap(WHITE_CELL_IMG));
		style_b->setCellPixmap(Chess::WHITE, Style::C_CHOICE, new QPixmap(HIGHLIGHT_WHITE_CELL_IMG));
		
		
		// BLACK CELLS
		style_b->setCellPixmap(Chess::BLACK, Style::C_STANDARD, new QPixmap(BLACK_CELL_IMG));
		style_b->setCellPixmap(Chess::BLACK, Style::C_CHOICE, new QPixmap(HIGHLIGHT_BLACK_CELL_IMG));
		
		
		// WHITE PIECES
		style_b->setPiecePixmap(Chess::WHITE, Piece::PAWN, Style::P_STANDARD, new QPixmap(WHITE_PAWN_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::PAWN, Style::P_SELECTED, new QPixmap(WHITE_SELECT_PAWN_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::PAWN, Style::P_CHOICE, new QPixmap(WHITE_CHOICE_PAWN_IMG));
		
		style_b->setPiecePixmap(Chess::WHITE, Piece::ROOK, Style::P_STANDARD, new QPixmap(WHITE_ROOK_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::ROOK, Style::P_SELECTED, new QPixmap(WHITE_SELECT_ROOK_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::ROOK, Style::P_CHOICE, new QPixmap(WHITE_CHOICE_ROOK_IMG));
		
		style_b->setPiecePixmap(Chess::WHITE, Piece::KNIGHT, Style::P_STANDARD, new QPixmap(WHITE_KNIGHT_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::KNIGHT, Style::P_SELECTED, new QPixmap(WHITE_SELECT_KNIGHT_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::KNIGHT, Style::P_CHOICE, new QPixmap(WHITE_CHOICE_KNIGHT_IMG));
		
		style_b->setPiecePixmap(Chess::WHITE, Piece::BISHOP, Style::P_STANDARD, new QPixmap(WHITE_BISHOP_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::BISHOP, Style::P_SELECTED, new QPixmap(WHITE_SELECT_BISHOP_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::BISHOP, Style::P_CHOICE, new QPixmap(WHITE_CHOICE_BISHOP_IMG));
		
		style_b->setPiecePixmap(Chess::WHITE, Piece::QUEEN, Style::P_STANDARD, new QPixmap(WHITE_QUEEN_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::QUEEN, Style::P_SELECTED, new QPixmap(WHITE_SELECT_QUEEN_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::QUEEN, Style::P_CHOICE, new QPixmap(WHITE_CHOICE_QUEEN_IMG));
		
		style_b->setPiecePixmap(Chess::WHITE, Piece::KING, Style::P_STANDARD, new QPixmap(WHITE_KING_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::KING, Style::P_SELECTED, new QPixmap(WHITE_SELECT_KING_IMG));
		style_b->setPiecePixmap(Chess::WHITE, Piece::KING, Style::P_CHOICE, new QPixmap(WHITE_CHOICE_KING_IMG));
		
		// BLACK PIECES
		style_b->setPiecePixmap(Chess::BLACK, Piece::PAWN, Style::P_STANDARD, new QPixmap(BLACK_PAWN_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::PAWN, Style::P_SELECTED, new QPixmap(BLACK_SELECT_PAWN_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::PAWN, Style::P_CHOICE, new QPixmap(BLACK_CHOICE_PAWN_IMG));
		
		style_b->setPiecePixmap(Chess::BLACK, Piece::ROOK, Style::P_STANDARD, new QPixmap(BLACK_ROOK_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::ROOK, Style::P_SELECTED, new QPixmap(BLACK_SELECT_ROOK_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::ROOK, Style::P_CHOICE, new QPixmap(BLACK_CHOICE_ROOK_IMG));
		
		style_b->setPiecePixmap(Chess::BLACK, Piece::KNIGHT, Style::P_STANDARD, new QPixmap(BLACK_KNIGHT_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::KNIGHT, Style::P_SELECTED, new QPixmap(BLACK_SELECT_KNIGHT_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::KNIGHT, Style::P_CHOICE, new QPixmap(BLACK_CHOICE_KNIGHT_IMG));
		
		style_b->setPiecePixmap(Chess::BLACK, Piece::BISHOP, Style::P_STANDARD, new QPixmap(BLACK_BISHOP_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::BISHOP, Style::P_SELECTED, new QPixmap(BLACK_SELECT_BISHOP_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::BISHOP, Style::P_CHOICE, new QPixmap(BLACK_CHOICE_BISHOP_IMG));
		
		style_b->setPiecePixmap(Chess::BLACK, Piece::QUEEN, Style::P_STANDARD, new QPixmap(BLACK_QUEEN_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::QUEEN, Style::P_SELECTED, new QPixmap(BLACK_SELECT_QUEEN_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::QUEEN, Style::P_CHOICE, new QPixmap(BLACK_CHOICE_QUEEN_IMG));
		
		style_b->setPiecePixmap(Chess::BLACK, Piece::KING, Style::P_STANDARD, new QPixmap(BLACK_KING_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::KING, Style::P_SELECTED, new QPixmap(BLACK_SELECT_KING_IMG));
		style_b->setPiecePixmap(Chess::BLACK, Piece::KING, Style::P_CHOICE, new QPixmap(BLACK_CHOICE_KING_IMG));
		
	
		curstyle = style_b;
	}
	catch(Exception* e)
	{	throw e;	}
}

StyleManager::~StyleManager()
{	delete curstyle;	}

void	StyleManager::setStyle(string filename)
{
	try
	{
		StyleBuilder*	builder = new StyleBuilder();
		builder->loadStyleFile(filename);
	}
	catch(Exception* e)
	{	throw e;	}
}


Style*	StyleManager::getStyle()
{	return (this->curstyle);	}

